﻿using MengRan.Models;
using MengRan.Models.index;
using MengRan.Models.test;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace MengRan.Controllers.api
{
    [ApiController]
    [Route("Home/api/[controller]/[action]")]
    public class chatController : Controller
    {
        private readonly MyDbContext _dbContext;
        public chatController(MyDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        [HttpGet]
        public IActionResult chatmes(string use, string mes)
        {
            var a = "";
            using (_dbContext)
            {
                var chatq = new chatmes
                {
                    name = use,
                    mess = mes,
                    datatime = DateTime.Now
                };
                _dbContext.chatmess.Add(chatq);
                var i = _dbContext.SaveChanges();
                a = i > 0 ? "数据写入成功" : "数据写入失败";
            }
            return Ok(a);
        }
       
    }
}
